﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TrackSystem.Entities.Extensions;
using TrackSystem.Entities.Models;

namespace TrackSystem.EntityFramework
{
    public static class DataSeed
    {
        public static readonly EquipTable[] Equips =
        {
            new EquipTable()
            {
                Id = 1,
                Name = "ROV",
                Description = "4500m级遥控潜水器"
            },

            new EquipTable()
            {
                Id = 2,
                Name = "UPPER",
                Description = "4500M中继器"
            }

        };

        public static readonly ChannelTable[] Chns =
        {
            new ChannelTable
            {
                Id = 1,
                Name = "Port1",
                Description = "Port for TCP",
                PortCategory = PortCategory.TCP,
                Ip = "127.0.0.1",
                Port = 4001,
                localIp = "",
                localPort = 0,
                COMn = "",
                Baudrate = 0,
                Protocol = ProtocolEnum.Modbus,
                optSupport21Cmd = true,
                optSplit3_4Cmd = false,
                Interval = 50
            },
            new ChannelTable
            {
                Id = 2,
                Name = "Port2",
                Description = "Port for UDP",
                PortCategory = PortCategory.UDP,
                Ip = "127.0.0.1",
                Port = 4002,
                localIp = "127.0.0.1",
                localPort = 5002,
                COMn = "",
                Baudrate = 0,
                Protocol = ProtocolEnum.Modbus,
                optSupport21Cmd = true,
                optSplit3_4Cmd = false,
                Interval = 50
            },
            new ChannelTable
            {
                Id = 3,
                Name = "Port3",
                Description = "Port for SERIAL",
                PortCategory = PortCategory.SRIAL,
                Ip = "",
                Port = 0,
                localIp = "",
                localPort = 0,
                COMn = "COM1",
                Baudrate = 38400,
                SerialParams = "N-8-1",
                Protocol = ProtocolEnum.CTD,
                optSupport21Cmd = true,
                optSplit3_4Cmd = false,
                Interval = 50
            }
        };

        public static readonly SensorTable[] Sensors =
        {
            new SensorTable { Id = 1,
                Name="PowerCtl",
                Description="电源监测",
                Station=1,
                RO_Address=0,
                RO_Length=0,
                RW_Address=0,
                RW_Length=2,
                Eabled=true,
                channelID = 1,
                equipId = 1
                },
            new SensorTable { Id = 2,
                Name="LeakDetect",
                Description="漏水监测",
                Station=2,
                RO_Address=0,
                RO_Length=3,
                RW_Address=0,
                RW_Length=3,
                Eabled=true,
                channelID = 1,
                equipId = 1
                },
            new SensorTable { Id = 3,
                Name="MotorTemp",
                Description="电机控制",
                Station=1,
                RO_Address=0,
                RO_Length=2,
                RW_Address=0,
                RW_Length=2,
                Eabled=true,
                channelID = 2,
                equipId = 2
               },
            new SensorTable { Id = 4,
                Name="CTD1",
                Description="CTD传感器",
                Station=2,
                RO_Address=0,
                RO_Length=5,
                RW_Address=0,
                RW_Length=5,
                Eabled=true,
                channelID = 3,
                equipId = 2
                },
        };

        public static readonly VarTable[] Vars =
        {
            new VarTable
            {
                Id = 1,
                Name = "Port1_Enable",
                Description = "Var from channel",
                Serial = VarSerialEnum.Attr_Channel,
                snrloopId = 1,
                snrloopIndex = 0,
                ReadOnly = false,
                DataType = DataTypeEnum.BOOLEAN,
                AlarmSetting = AlarmTypeEnum.None,
            },
            new VarTable
            {
                Id = 2,
                Name = "Port2_Enable",
                Description = "Var from channel",
                Serial = VarSerialEnum.Attr_Channel,
                snrloopId = 1,
                snrloopIndex = 1,
                ReadOnly = true,
                DataType = DataTypeEnum.BOOLEAN,
                AlarmSetting = AlarmTypeEnum.None,
           },
            new VarTable
            {
                Id = 3,
                Name = "Port1_Cycle",
                Description = "Var from channel",
                Serial = VarSerialEnum.Attr_Channel,
                snrloopId = 1,
                snrloopIndex = 2,
                ReadOnly = true,
                DataType = DataTypeEnum.INTEGER,
                AlarmSetting = AlarmTypeEnum.None,
           },
            new VarTable
            {
                Id = 4,
                Name = "Port1_Lapse",
                Description = "Var from channel",
                Serial = VarSerialEnum.Attr_Channel,
                snrloopId = 1,
                snrloopIndex = 3,
                ReadOnly = true,
                DataType = DataTypeEnum.BOOLEAN,
                AlarmSetting = AlarmTypeEnum.None,
            },
            new VarTable
            {
                Id = 5,
                Name = "Port2_Enabled",
                Description = "Var from channel",
                Serial = VarSerialEnum.Attr_Channel,
                snrloopId = 2,
                snrloopIndex = 0,
                ReadOnly = false,
                DataType = DataTypeEnum.BOOLEAN,
                AlarmSetting = AlarmTypeEnum.None,
            },
            new VarTable
            {
                Id = 6,
                Name = "Port2_Connected",
                Description = "Var from channel",
                Serial = VarSerialEnum.Attr_Channel,
                snrloopId = 2,
                snrloopIndex = 1,
                ReadOnly = true,
                DataType = DataTypeEnum.BOOLEAN,
                AlarmSetting = AlarmTypeEnum.None,
            },
            new VarTable
            {
                Id = 7,
                Name = "Port2_Cycle",
                Description = "Var from channel",
                Serial = VarSerialEnum.Attr_Channel,
                snrloopId = 2,
                snrloopIndex = 2,
                ReadOnly = true,
                DataType = DataTypeEnum.INTEGER,
                AlarmSetting = AlarmTypeEnum.None,
            },
            new VarTable
            {
                Id = 8,
                Name = "Port2_Lapse",
                Description = "Var from channel",
                Serial = VarSerialEnum.Attr_Channel,
                snrloopId = 2,
                snrloopIndex = 3,
                ReadOnly = true,
                DataType = DataTypeEnum.INTEGER,
                AlarmSetting = AlarmTypeEnum.None,
            },
            new VarTable
            {
                Id = 9,
                Name = "Port3_Enabled",
                Description = "Var from channel",
                Serial = VarSerialEnum.Attr_Channel,
                snrloopId = 3,
                snrloopIndex = 0,
                ReadOnly = false,
                DataType = DataTypeEnum.BOOLEAN,
                AlarmSetting = AlarmTypeEnum.None,
            },
            new VarTable
            {
                Id = 10,
                Name = "Port3_Connected",
                Description = "Var from channel",
                Serial = VarSerialEnum.Attr_Channel,
                snrloopId = 3,
                snrloopIndex = 1,
                ReadOnly = true,
                DataType = DataTypeEnum.BOOLEAN,
                AlarmSetting = AlarmTypeEnum.None,
            },
            new VarTable
            {
                Id = 11,
                Name = "Port3_Cycle",
                Description = "Var from channel",
                Serial = VarSerialEnum.Attr_Channel,
                snrloopId = 3,
                snrloopIndex = 2,
                ReadOnly = true,
                DataType = DataTypeEnum.INTEGER,
                AlarmSetting = AlarmTypeEnum.None,
            },
            new VarTable
            {
                Id = 12,
                Name = "DestDepth",
                Description = "定深目标值",
                Serial = VarSerialEnum.UserDefine,
                snrloopId = 0,
                snrloopIndex = 0,
                ReadOnly = false,
                DataType = DataTypeEnum.DOUBLE,
                AlarmSetting = AlarmTypeEnum.None,
            }
        };

        public static readonly LogicTable[] Logics =
        {
            new LogicTable
            {
                Id = 1,
                Name = "Logic1",
                Description = "Logic for Port1",
                Enabled = true,
                ConditionFormula = "Port1_Connected",
                ClacateFormula = "MotorTemp_RW1 = Port3_Enable ? int(rand(Port2_Lapse )) : 0;",
                ResultReg = "MotorTemp_RW1",
                UpdateWhenChanged = true,
                equipId = 1
            },
            new LogicTable
            {
                Id = 2,
                Name = "Logic2",
                Description = "Logic for Port2",
                Enabled = true,
                ConditionFormula = "Port2_Enable",
                ClacateFormula = "MotorTemp_RW2 = Port1_Connected ?int(rand(400)) : 0;",
                ResultReg = "MotorTemp_RW2",
                UpdateWhenChanged = true,
                equipId = 2
            }
        };

        public static readonly LoopTable[] Loops =
        [
            new LoopTable {
                Id = 1,
                Name = "AutoDepth",
                Description = "定深控制回路",
                PVName = "MotorTemp_RW1",
                SVName = "DestDepth",
                OPName = "MotorTemp_RW4",
                Method = LoopMethod.PID,
                Action = true,
                Dirction = true,
                Params_P = 1.5,
                Params_I = 0.5,
                Params_D = 0.24,
                OutHLimit = 100,
                OutLLimit = -100,
                Setting = "",
                PDeadZone = 10,
                NDeadZone = 10,
                Ratio = 1.0,
                equipId = 1
            }
        ];

        public static readonly SlaveTable[]  Slaves =  [
            new SlaveTable
            {
                Id = 1,
                Name = "HMIData",
                Description = "HMI接口数据服务器",
                Protocol = SlaveProtocol.Modbus_TCP,
                PortCategory = PortCategory.TCP,
                RemoteIP = "127.0.0.1",
                RemotePort = 7010,
                LocalIP = "127.0.0.1",
                LocalPort = 6001,
                Comx = "COM1",
                BaudRate = 9600,
                SerialParams = "N-8-1",
                Station = 1,
                RoList = "MotorTemp_RO0,MotorTemp_RO1,MotorTemp_RO2",
                RwList = "MotorTemp_RW0,MotorTemp_RW1,MotorTemp_RW2,MotorTemp_RW3",
                ProtocolDefine = "",
                Cycle = 100
            }
        ];
    }
}
